<template>
  <div class="biz-container">
    <batch-operat-btn>
      <template #cusBtn>
        <a-button
          type="primary"
          icon="plus-circle"
          @click="onAdd"
          size="small"
        > 新增发票 </a-button>
      </template>
    </batch-operat-btn>
    <a-list-table
      style="marginTop:5px"
      tableId="invoicesTable1"
      :columns="columns"
      :tableData="listdata"
      :pagination="pagination"
      :isSelecttion="false"
      :loading="loading"
      :scroll="{y:null}"
      @onTableChange="handleTableChange"
      @onselectChange="onselectChange"
      @onAction="onAction"
      :links="links"
      @onTouchlinkCell="onTouchlinkCell"
    >
    </a-list-table>
    
    <addModal
      ref="addModal"
      @onSubmit="onSubmit"
      @ok="handleModalSaveOk"
      @close="handleModalCancel"
    />
  </div>
</template>

<script>
import searchLayout from '@/views/app/biz/common/searchLayout'
import batchOperatBtn from '@/views/app/biz/common/batchOperatBtn'
import tableLayout from '@/views/app/biz/common/index'
import aListInfo from '@/views/app/biz/common/aListInfo'
import aListTable from '@/views/app/biz/common/aListTable'
import addModal from './addModal.vue'
import moment from 'moment'
import {
  getDetailByConditions,
  getDetailByConditionsCount,
} from '../saleOrder/saleOrder'
import {
  invoColumns
} from './mergeStepConfig'


let links = ['saleOrderNo',]

export default {
  components: {
    searchLayout,
    batchOperatBtn,
    tableLayout,
    aListInfo,
    aListTable,
    addModal
  },
  data () {
    return {
      columns: invoColumns,
      listdata: [],
      links: links,
      loading: false,
      pagination: {
        //分页配置
        current: 1, //当前页码 current
        pageSize: 10, //每页显示条数 pageSize
        total: 1,
        showQuickJumper: true,
        showSizeChanger: true,
        pageSizeOptions: ['2', '10', '50', '100'],
      },
      // 查询表单
      q_formInfos: [
        { label: '销售单号', name: 'saleOrderNo', type: 'input', placeholder: '销售单号' },
        { label: '客户名称', name: 'customerName', type: 'customer', placeholder: '客户名称' },
        { label: ['查询', '重置'], type: 'botton' }
      ],
      // 查询表单绑定数据
      q_formDatas: {
        saleOrderPid: "4a421c5e8bc2444b981c575584d94299",
        // saleOrderNo: null,
        // customerName: null,
        // saleOrderState:'待配送'
      },
      pData: {}, // 条件查询参数
      isJump: false,
      optText: '确认订单',
      selectedRowKeys: [],
      selectedRows: [],
      notAudit: false,
    }
  },
  computed: {},

  mounted () {
    // this.getTotal()
    // this.getList(this.q_formDatas)

  },
  methods: {
    // 初始化页面时得到总数
    async getTotal () {

    },
    // 初始化查询时的数据列表
    async getList (params) {

    },
    // 关闭模态详细框
    handleModalCancel () {
    },
    // 模态详细框提交按钮
    handleModalSaveOk () {
      this.getList(this.q_formDatas)
    },
    onAdd () {
      this.$refs.addModal.addModal()
    },
    onSubmit (val) {
      console.log(val);
      this.listdata.push({
        key: moment(new Date).format("YYYYMMDDhhmmss"),
        ...val,
        action: ['删除']
      })
    },
    // 操作按钮
    onAction (text, record, index) {
      if (text == '删除') {
        this.listdata.splice(index, 1)
      }
    },
    // 触发改变页码,筛选,排序时的回调
    handleTableChange (pagination, filters, sorter) {
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      this.getList(this.q_formDatas)
    },
    // 查询按钮
    onFind () {
      this.pagination.current = 1
      this.getTotal()
      this.getList(this.q_formDatas)
    },

    onTouchlinkCell (text, record, index, link) {
      console.log(record);
      if (link == 'saleOrderNo') {
        this.$refs.viewSaleOrderModal.showModal(record.pid, record)
      }
    },
    // 多选批量操作
    onselectChange (selectedRowKeys, selectedRows) {
    },
    onNext () {
      if (this.listdata.length) {
        this.$emit('onNextStep', this.listdata)
      } else {
        this.$message.warning({ content: '未添加发票信息', duration: 3 })
      }
    },
    onJump () {
      this.listdata = []
      this.$emit('onNextStep', this.listdata)
    },
    onPrevious () {
      this.$emit('onPrevious')
    }
  },
}
</script>

<style>
</style>